﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace BaoJian.eshop.mn
{
    public partial class orderCfmApp : System.Web.UI.Page
    {
        private WebProfile Profile
        {
            get { return new WebProfile(Context.Profile); }
        }
        private string addressNUM;
        public LYQ.Model.GuestAddress guestAddressModel;
        public double TotalPrice;
        public double TotalMarketPrice;
        public string NextURL;

        protected void Page_Load(object sender, EventArgs e)
        {
            addressNUM = HttpContext.Current.Request.QueryString["a"];
            if (!Page.IsPostBack)
            {

                LYQ.BLL.GuestAddress addBll = new LYQ.BLL.GuestAddress();
                guestAddressModel = addBll.GetModel(Convert.ToInt32(addressNUM));
                BindData();
            }
        }



       private void BindData()
        {
            string[] sel;
            if (Profile.IsAnonymous)
            {
                sel = Profile.CustomerSelect.Split(';');
            }
            else
            {
                sel = Profile.CustomerSelect.Split(';');
            }

            string sql = null;
            string[] tmp;
            for (int i = 0; i < sel.Length; i++)
            {
                tmp = sel[i].Split(',');
                if (i == 0)
                {
                    sql += " PID=''" + tmp[0] + "'' ";
                }
                else
                {
                    sql += " or  PID=''" + tmp[0] + "''";
                }
            }

            using (DataSet ds = Tools.Common.GetPage("EProduct", "[Name],[PID],[MarketPrice],[Price],0 as NUM", "SID ",
                  1000, 1, false, true, sql, "PID"))
            {
                DataTable dt = ds.Tables[0];

                for (int s = 0; s < sel.Length; s++)
                {
                    tmp = sel[s].Split(',');
                    for (int t = 0; t < dt.Rows.Count; t++)
                    {
                        if (tmp[0] == dt.Rows[t][1].ToString())
                        {
                            dt.Rows[t][4] = Convert.ToInt32(tmp[1]);

                            TotalPrice += Convert.ToDouble(dt.Rows[t][3]) * Convert.ToDouble(tmp[1]);
                            TotalMarketPrice += Convert.ToDouble(dt.Rows[t][2]) * Convert.ToDouble(tmp[1]);

                            break;
                        }


                    }
                }
                DataList1.DataSource = ds.Tables[0];
                DataList1.DataBind();
            }


        }
    }
}
